package cn.zebra.dev.product.moudle.brand.service.impl;

import cn.zebra.dev.ibatis.plus.service.impl.ServiceImpl;
import cn.zebra.dev.ibatis.plus.utils.PageUtils;
import cn.zebra.dev.ibatis.plus.utils.Query;
import cn.zebra.dev.product.moudle.brand.dao.BrandDao;
import cn.zebra.dev.product.moudle.brand.entity.BrandEntity;
import cn.zebra.dev.product.moudle.brand.service.BrandService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * 商品品牌表
 *
 * @author runnable
 */
@Service
public class BrandServiceImpl extends ServiceImpl<BrandDao, BrandEntity> implements BrandService {

    @Override
    public PageUtils<BrandEntity> findPage(Map<String, Object> params) {
        QueryWrapper<BrandEntity> wrapper = new QueryWrapper<>();
        IPage<BrandEntity> page = this.page(
                new Query<BrandEntity>(params).getPage(),
                wrapper
        );

        return new PageUtils<>(page);
    }

    @Override
    public List<BrandEntity> findALL() {
        QueryWrapper<BrandEntity> wrapper = new QueryWrapper<>();
        wrapper.select("id, brand_name, brand_message, brand_category_id ");
        return list(wrapper);
    }

    @Override
    public List<BrandEntity> findBrandByCategory(Long categoryId) {
        QueryWrapper<BrandEntity> wrapper = new QueryWrapper<>();
        wrapper.select("id, brand_name");
        wrapper.apply("brand_category_id = {0}",categoryId);
        return list(wrapper);
    }

    @Override
    public Boolean updateProductBrand(Long id, BrandEntity entity) {
        return update(entity, "id = {0} AND delete_flag = FALSE", id);
    }


}
